package myapp.baselibrary;

import android.content.Context;
import android.util.Log;

/**
 * Created by yang2 on 2017/6/13.
 */

public class ExceptionCrashHandler implements Thread.UncaughtExceptionHandler {
    private static ExceptionCrashHandler mInstance;
    private static Context mContext;

    private static Thread.UncaughtExceptionHandler mDefaultExceptionHandler;
    public static  ExceptionCrashHandler getInstance(){
        if (mInstance==null){
            synchronized (ExceptionCrashHandler.class){
                if (mInstance == null){
                    mInstance = new ExceptionCrashHandler();
                }
            }
        }
        return mInstance;
    }
    public  void init(Context context){

        ExceptionCrashHandler.mContext = context;
        Thread.currentThread().setUncaughtExceptionHandler(ExceptionCrashHandler.this);
        mDefaultExceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
    }

    /**
     * @param thread
     * @param t
     */
    public void uncaughtException(Thread thread,Throwable t){
        Log.d("tag","报错");
        mDefaultExceptionHandler.uncaughtException(thread,t);
    }
}
